﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;

namespace DissipativeInputProcessing
{
    class FrameFileProxy : IFrame
    {
        private IFrame _target;
        private FileInfo _file;
        private bool _targetUpToDate = false;
        public FrameFileProxy(FileInfo file, IFrame frame)
        {
            _file = file;
            _target = frame;

        }
        private IFrame GetTarget()
        {
            if (!_targetUpToDate)
            {
                float[,] matrix;
                using (var reader = new StreamReader(_file.FullName))
                    matrix = InputParsing.InputParser.Instance.ParseToMatrix(reader);
                _target.SourceData = matrix;
                _targetUpToDate = true;
            }
            return _target;
        }
        public Bitmap Image
        {
            get { return GetTarget().Image; }
        }

        public FramePalette Palette
        {
            get { return _target.Palette; }
            set { _target.Palette = value; }
        }

        public float[,] SourceData
        {
            get { return GetTarget().SourceData; }
            set { _target.SourceData = value; }
        }

        public void Update()
        {
            GetTarget().Update();
        }

        public void Update(bool instantly)
        {
            GetTarget().Update(instantly);
        }

        public string Description
        {
            get { return _file.Name; }
        }

        public bool IsUpToDate
        {
            get { return _target.IsUpToDate; }
        }

        public float MinSourceValue
        {
            get { return GetTarget().MinSourceValue; }
        }

        public float MaxSourceValue
        {
            get { return GetTarget().MaxSourceValue; }
        }
    }
}
